<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
	<title>format | ElasticSearch 7.7 权威指南中文版</title>
	<meta name="keywords" content="ElasticSearch 权威指南中文版, elasticsearch 7, es7, 实时数据分析，实时数据检索" />
    <meta name="description" content="ElasticSearch 权威指南中文版, elasticsearch 7, es7, 实时数据分析，实时数据检索" />
    <!-- Give IE8 a fighting chance -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
	<link rel="stylesheet" type="text/css" href="../static/styles.css" />
	<script>
	var _link = 'mapping-date-format.html';
    </script>
</head>
<body>
<div class="main-container">
    <section id="content">
        <div class="content-wrapper">
            <section id="guide" lang="zh_cn">
                <div class="container">
                    <div class="row">
                        <div class="col-xs-12 col-sm-8 col-md-8 guide-section">
                            <div style="color:gray; word-break: break-all; font-size:12px;">原英文版地址: <a href="https://www.elastic.co/guide/en/elasticsearch/reference/7.7/mapping-date-format.html" rel="nofollow" target="_blank">https://www.elastic.co/guide/en/elasticsearch/reference/7.7/mapping-date-format.html</a>, 原文档版权归 www.elastic.co 所有<br/>本地英文版地址: <a href="../en/mapping-date-format.html" rel="nofollow" target="_blank">../en/mapping-date-format.html</a></div>
                        <!-- start body -->
                  <div class="page_header">
<strong>重要</strong>: 此版本不会发布额外的bug修复或文档更新。最新信息请参考 <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html" rel="nofollow">当前版本文档</a>。
</div>
<div id="content">
<div class="breadcrumbs">
<span class="breadcrumb-link"><a href="index.html">Elasticsearch Guide [7.7]</a></span>
»
<span class="breadcrumb-link"><a href="mapping.html">Mapping</a></span>
»
<span class="breadcrumb-link"><a href="mapping-params.html">Mapping parameters</a></span>
»
<span class="breadcrumb-node"><code class="literal">format</code></span>
</div>
<div class="navheader">
<span class="prev">
<a href="fielddata.html">« <code class="literal">fielddata</code></a>
</span>
<span class="next">
<a href="ignore-above.html"><code class="literal">ignore_above</code> »</a>
</span>
</div>
<div class="section">
<div class="titlepage"><div><div>
<h2 class="title">
<a id="mapping-date-format"></a><code class="literal">format</code><a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/mapping/params/format.asciidoc">edit</a>
</h2>
</div></div></div>
<p>In JSON documents, dates are represented as strings. Elasticsearch uses a set
of preconfigured formats to recognize and parse these strings into a long
value representing <em>milliseconds-since-the-epoch</em> in UTC.</p>
<p>Besides the <a class="xref" href="mapping-date-format.html#built-in-date-formats" title="Built In Formats">built-in formats</a>, your own
<a class="xref" href="mapping-date-format.html#custom-date-formats" title="Custom date formats">custom formats</a> can be specified using the familiar
<code class="literal">yyyy/MM/dd</code> syntax:</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">PUT my_index
{
  "mappings": {
    "properties": {
      "date": {
        "type":   "date",
        "format": "yyyy-MM-dd"
      }
    }
  }
}</pre>
</div>
<div class="console_widget" data-snippet="snippets/760.console"></div>
<p>Many APIs which support date values also support <a class="xref" href="common-options.html#date-math" title="Date Math">date math</a>
expressions, such as <code class="literal">now-1m/d</code> — the current time, minus one month, rounded
down to the nearest day.</p>
<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="custom-date-formats"></a>Custom date formats<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/mapping/params/format.asciidoc">edit</a>
</h3>
</div></div></div>
<p>Completely customizable date formats are supported.  The syntax for these is explained
<a href="https://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html" class="ulink" target="_top">DateTimeFormatter docs</a>.</p>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="built-in-date-formats"></a>Built In Formats<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/mapping/params/format.asciidoc">edit</a>
</h3>
</div></div></div>
<p>Most of the below formats have a <code class="literal">strict</code> companion format, which means that
year, month and day parts of the week must use respectively 4, 2 and 2 digits
exactly, potentially prepending zeros. For instance a date like <code class="literal">5/11/1</code> would
be considered invalid and would need to be rewritten to <code class="literal">2005/11/01</code> to be
accepted by the date parser.</p>
<p>To use them, you need to prepend <code class="literal">strict_</code> to the name of the date format, for
instance <code class="literal">strict_date_optional_time</code> instead of <code class="literal">date_optional_time</code>.</p>
<p>These strict date formats are especially useful when
<a class="xref" href="dynamic-field-mapping.html#date-detection" title="Date detection">date fields are dynamically mapped</a> in order to make sure to
not accidentally map irrelevant strings as dates.</p>
<p>The following tables lists all the defaults ISO formats supported:</p>
<div class="variablelist">
<dl class="variablelist">
<dt>
<span class="term">
<code class="literal">epoch_millis</code>
</span>
</dt>
<dd>
A formatter for the number of milliseconds since the epoch. Note, that
this timestamp is subject to the limits of a Java <code class="literal">Long.MIN_VALUE</code> and
<code class="literal">Long.MAX_VALUE</code>.
</dd>
<dt>
<span class="term">
<code class="literal">epoch_second</code>
</span>
</dt>
<dd>
A formatter for the number of seconds since the epoch. Note, that this
timestamp is subject to the limits of a Java <code class="literal">Long.MIN_VALUE</code> and <code class="literal">Long.
MAX_VALUE</code> divided by 1000 (the number of milliseconds in a second).
</dd>
<dt>
<span class="term">
<a id="strict-date-time"></a><code class="literal">date_optional_time</code> or <code class="literal">strict_date_optional_time</code>
</span>
</dt>
<dd>
A generic ISO datetime parser where the date, in <code class="literal">year_month_day</code> format, is
mandatory and the time, separated by <code class="literal">T</code>, is optional.
Examples: <code class="literal">yyyy-MM-dd'T'HH:mm:ss.SSSZ</code> or  <code class="literal">yyyy-MM-dd</code>.
</dd>
<dt>
<span class="term">
<code class="literal">basic_date</code>
</span>
</dt>
<dd>
A basic formatter for a full date as four digit year, two digit month of
year, and two digit day of month: <code class="literal">yyyyMMdd</code>.
</dd>
<dt>
<span class="term">
<code class="literal">basic_date_time</code>
</span>
</dt>
<dd>
A basic formatter that combines a basic date and time, separated by a <em>T</em>:
<code class="literal">yyyyMMdd'T'HHmmss.SSSZ</code>.
</dd>
<dt>
<span class="term">
<code class="literal">basic_date_time_no_millis</code>
</span>
</dt>
<dd>
A basic formatter that combines a basic date and time without millis,
separated by a <em>T</em>: <code class="literal">yyyyMMdd'T'HHmmssZ</code>.
</dd>
<dt>
<span class="term">
<code class="literal">basic_ordinal_date</code>
</span>
</dt>
<dd>
A formatter for a full ordinal date, using a four digit year and three
digit dayOfYear: <code class="literal">yyyyDDD</code>.
</dd>
<dt>
<span class="term">
<code class="literal">basic_ordinal_date_time</code>
</span>
</dt>
<dd>
A formatter for a full ordinal date and time, using a four digit year and
three digit dayOfYear: <code class="literal">yyyyDDD'T'HHmmss.SSSZ</code>.
</dd>
<dt>
<span class="term">
<code class="literal">basic_ordinal_date_time_no_millis</code>
</span>
</dt>
<dd>
A formatter for a full ordinal date and time without millis, using a four
digit year and three digit dayOfYear: <code class="literal">yyyyDDD'T'HHmmssZ</code>.
</dd>
<dt>
<span class="term">
<code class="literal">basic_time</code>
</span>
</dt>
<dd>
A basic formatter for a two digit hour of day, two digit minute of hour,
two digit second of minute, three digit millis, and time zone offset:
<code class="literal">HHmmss.SSSZ</code>.
</dd>
<dt>
<span class="term">
<code class="literal">basic_time_no_millis</code>
</span>
</dt>
<dd>
A basic formatter for a two digit hour of day, two digit minute of hour,
two digit second of minute, and time zone offset: <code class="literal">HHmmssZ</code>.
</dd>
<dt>
<span class="term">
<code class="literal">basic_t_time</code>
</span>
</dt>
<dd>
A basic formatter for a two digit hour of day, two digit minute of hour,
two digit second of minute, three digit millis, and time zone off set
prefixed by <em>T</em>: <code class="literal">'T'HHmmss.SSSZ</code>.
</dd>
<dt>
<span class="term">
<code class="literal">basic_t_time_no_millis</code>
</span>
</dt>
<dd>
A basic formatter for a two digit hour of day, two digit minute of hour,
two digit second of minute, and time zone offset prefixed by <em>T</em>:
<code class="literal">'T'HHmmssZ</code>.
</dd>
<dt>
<span class="term">
<code class="literal">basic_week_date</code> or <code class="literal">strict_basic_week_date</code>
</span>
</dt>
<dd>
A basic formatter for a full date as four digit weekyear, two digit week
of weekyear, and one digit day of week: <code class="literal">xxxx'W'wwe</code>.
</dd>
<dt>
<span class="term">
<code class="literal">basic_week_date_time</code> or <code class="literal">strict_basic_week_date_time</code>
</span>
</dt>
<dd>
A basic formatter that combines a basic weekyear date and time, separated
by a <em>T</em>: <code class="literal">xxxx'W'wwe'T'HHmmss.SSSZ</code>.
</dd>
<dt>
<span class="term">
<code class="literal">basic_week_date_time_no_millis</code> or <code class="literal">strict_basic_week_date_time_no_millis</code>
</span>
</dt>
<dd>
A basic formatter that combines a basic weekyear date and time without
millis, separated by a <em>T</em>: <code class="literal">xxxx'W'wwe'T'HHmmssZ</code>.
</dd>
<dt>
<span class="term">
<code class="literal">date</code> or <code class="literal">strict_date</code>
</span>
</dt>
<dd>
A formatter for a full date as four digit year, two digit month of year,
and two digit day of month: <code class="literal">yyyy-MM-dd</code>.
</dd>
<dt>
<span class="term">
<code class="literal">date_hour</code> or <code class="literal">strict_date_hour</code>
</span>
</dt>
<dd>
A formatter that combines a full date and two digit hour of day:
<code class="literal">yyyy-MM-dd'T'HH</code>.
</dd>
<dt>
<span class="term">
<code class="literal">date_hour_minute</code> or <code class="literal">strict_date_hour_minute</code>
</span>
</dt>
<dd>
A formatter that combines a full date, two digit hour of day, and two
digit minute of hour: <code class="literal">yyyy-MM-dd'T'HH:mm</code>.
</dd>
<dt>
<span class="term">
<code class="literal">date_hour_minute_second</code> or <code class="literal">strict_date_hour_minute_second</code>
</span>
</dt>
<dd>
A formatter that combines a full date, two digit hour of day, two digit
minute of hour, and two digit second of minute: <code class="literal">yyyy-MM-dd'T'HH:mm:ss</code>.
</dd>
<dt>
<span class="term">
<code class="literal">date_hour_minute_second_fraction</code> or <code class="literal">strict_date_hour_minute_second_fraction</code>
</span>
</dt>
<dd>
A formatter that combines a full date, two digit hour of day, two digit
minute of hour, two digit second of minute, and three digit fraction of
second: <code class="literal">yyyy-MM-dd'T'HH:mm:ss.SSS</code>.
</dd>
<dt>
<span class="term">
<code class="literal">date_hour_minute_second_millis</code> or <code class="literal">strict_date_hour_minute_second_millis</code>
</span>
</dt>
<dd>
A formatter that combines a full date, two digit hour of day, two digit
minute of hour, two digit second of minute, and three digit fraction of
second: <code class="literal">yyyy-MM-dd'T'HH:mm:ss.SSS</code>.
</dd>
<dt>
<span class="term">
<code class="literal">date_time</code> or <code class="literal">strict_date_time</code>
</span>
</dt>
<dd>
A formatter that combines a full date and time, separated by a <em>T</em>:
<code class="literal">yyyy-MM-dd'T'HH:mm:ss.SSSZZ</code>.
</dd>
<dt>
<span class="term">
<code class="literal">date_time_no_millis</code> or <code class="literal">strict_date_time_no_millis</code>
</span>
</dt>
<dd>
A formatter that combines a full date and time without millis, separated
by a <em>T</em>: <code class="literal">yyyy-MM-dd'T'HH:mm:ssZZ</code>.
</dd>
<dt>
<span class="term">
<code class="literal">hour</code> or <code class="literal">strict_hour</code>
</span>
</dt>
<dd>
A formatter for a two digit hour of day: <code class="literal">HH</code>
</dd>
<dt>
<span class="term">
<code class="literal">hour_minute</code> or <code class="literal">strict_hour_minute</code>
</span>
</dt>
<dd>
A formatter for a two digit hour of day and two digit minute of hour:
<code class="literal">HH:mm</code>.
</dd>
<dt>
<span class="term">
<code class="literal">hour_minute_second</code> or <code class="literal">strict_hour_minute_second</code>
</span>
</dt>
<dd>
A formatter for a two digit hour of day, two digit minute of hour, and two
digit second of minute: <code class="literal">HH:mm:ss</code>.
</dd>
<dt>
<span class="term">
<code class="literal">hour_minute_second_fraction</code> or <code class="literal">strict_hour_minute_second_fraction</code>
</span>
</dt>
<dd>
A formatter for a two digit hour of day, two digit minute of hour, two
digit second of minute, and three digit fraction of second: <code class="literal">HH:mm:ss.SSS</code>.
</dd>
<dt>
<span class="term">
<code class="literal">hour_minute_second_millis</code> or <code class="literal">strict_hour_minute_second_millis</code>
</span>
</dt>
<dd>
A formatter for a two digit hour of day, two digit minute of hour, two
digit second of minute, and three digit fraction of second: <code class="literal">HH:mm:ss.SSS</code>.
</dd>
<dt>
<span class="term">
<code class="literal">ordinal_date</code> or <code class="literal">strict_ordinal_date</code>
</span>
</dt>
<dd>
A formatter for a full ordinal date, using a four digit year and three
digit dayOfYear: <code class="literal">yyyy-DDD</code>.
</dd>
<dt>
<span class="term">
<code class="literal">ordinal_date_time</code> or <code class="literal">strict_ordinal_date_time</code>
</span>
</dt>
<dd>
A formatter for a full ordinal date and time, using a four digit year and
three digit dayOfYear: <code class="literal">yyyy-DDD'T'HH:mm:ss.SSSZZ</code>.
</dd>
<dt>
<span class="term">
<code class="literal">ordinal_date_time_no_millis</code> or <code class="literal">strict_ordinal_date_time_no_millis</code>
</span>
</dt>
<dd>
A formatter for a full ordinal date and time without millis, using a four
digit year and three digit dayOfYear: <code class="literal">yyyy-DDD'T'HH:mm:ssZZ</code>.
</dd>
<dt>
<span class="term">
<code class="literal">time</code> or <code class="literal">strict_time</code>
</span>
</dt>
<dd>
A formatter for a two digit hour of day, two digit minute of hour, two
digit second of minute, three digit fraction of second, and time zone
offset: <code class="literal">HH:mm:ss.SSSZZ</code>.
</dd>
<dt>
<span class="term">
<code class="literal">time_no_millis</code> or <code class="literal">strict_time_no_millis</code>
</span>
</dt>
<dd>
A formatter for a two digit hour of day, two digit minute of hour, two
digit second of minute, and time zone offset: <code class="literal">HH:mm:ssZZ</code>.
</dd>
<dt>
<span class="term">
<code class="literal">t_time</code> or <code class="literal">strict_t_time</code>
</span>
</dt>
<dd>
A formatter for a two digit hour of day, two digit minute of hour, two
digit second of minute, three digit fraction of second, and time zone
offset prefixed by <em>T</em>: <code class="literal">'T'HH:mm:ss.SSSZZ</code>.
</dd>
<dt>
<span class="term">
<code class="literal">t_time_no_millis</code> or <code class="literal">strict_t_time_no_millis</code>
</span>
</dt>
<dd>
A formatter for a two digit hour of day, two digit minute of hour, two
digit second of minute, and time zone offset prefixed by <em>T</em>: <code class="literal">'T'HH:mm:ssZZ</code>.
</dd>
<dt>
<span class="term">
<code class="literal">week_date</code> or <code class="literal">strict_week_date</code>
</span>
</dt>
<dd>
A formatter for a full date as four digit weekyear, two digit week of
weekyear, and one digit day of week: <code class="literal">xxxx-'W'ww-e</code>.
</dd>
<dt>
<span class="term">
<code class="literal">week_date_time</code> or <code class="literal">strict_week_date_time</code>
</span>
</dt>
<dd>
A formatter that combines a full weekyear date and time, separated by a
<em>T</em>: <code class="literal">xxxx-'W'ww-e'T'HH:mm:ss.SSSZZ</code>.
</dd>
<dt>
<span class="term">
<code class="literal">week_date_time_no_millis</code> or <code class="literal">strict_week_date_time_no_millis</code>
</span>
</dt>
<dd>
A formatter that combines a full weekyear date and time without millis,
separated by a <em>T</em>: <code class="literal">xxxx-'W'ww-e'T'HH:mm:ssZZ</code>.
</dd>
<dt>
<span class="term">
<code class="literal">weekyear</code> or <code class="literal">strict_weekyear</code>
</span>
</dt>
<dd>
A formatter for a four digit weekyear: <code class="literal">xxxx</code>.
</dd>
<dt>
<span class="term">
<code class="literal">weekyear_week</code> or <code class="literal">strict_weekyear_week</code>
</span>
</dt>
<dd>
A formatter for a four digit weekyear and two digit week of weekyear:
<code class="literal">xxxx-'W'ww</code>.
</dd>
<dt>
<span class="term">
<code class="literal">weekyear_week_day</code> or <code class="literal">strict_weekyear_week_day</code>
</span>
</dt>
<dd>
A formatter for a four digit weekyear, two digit week of weekyear, and one
digit day of week: <code class="literal">xxxx-'W'ww-e</code>.
</dd>
<dt>
<span class="term">
<code class="literal">year</code> or <code class="literal">strict_year</code>
</span>
</dt>
<dd>
A formatter for a four digit year: <code class="literal">yyyy</code>.
</dd>
<dt>
<span class="term">
<code class="literal">year_month</code> or <code class="literal">strict_year_month</code>
</span>
</dt>
<dd>
A formatter for a four digit year and two digit month of year: <code class="literal">yyyy-MM</code>.
</dd>
<dt>
<span class="term">
<code class="literal">year_month_day</code> or <code class="literal">strict_year_month_day</code>
</span>
</dt>
<dd>
A formatter for a four digit year, two digit month of year, and two digit
day of month: <code class="literal">yyyy-MM-dd</code>.
</dd>
</dl>
</div>
</div>

</div>
<div class="navfooter">
<span class="prev">
<a href="fielddata.html">« <code class="literal">fielddata</code></a>
</span>
<span class="next">
<a href="ignore-above.html"><code class="literal">ignore_above</code> »</a>
</span>
</div>
</div>

                  <!-- end body -->
                        </div>
                        <div class="col-xs-12 col-sm-4 col-md-4" id="right_col">
                        
                        </div>
                    </div>
                </div>
            </section>
        </div>
    </section>
</div>
<script src="../static/cn.js"></script>
</body>
</html>